package com.heima.freemaker.controller;

import com.heima.freemaker.enity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2022/1/4 19:02
 */
@Controller
public class FreemakerController {


    @GetMapping("/basic")
    public String hell(Model model){

        // 纯文本形式的参数
        model.addAttribute("name", "freemaker");

        Student student = new Student();
        student.setName("小明");
        student.setAge(19);

        model.addAttribute("stu", student);
        return "01-basic";
    }

    @GetMapping("/list")
    public String list(Model model){

        Student stu1 = new Student();
        stu1.setAge(19);
        stu1.setName("小黑");
        stu1.setBirthday(new Date());
        stu1.setMoney(19f);

        Student stu2 = new Student();
        stu2.setAge(20);
        stu2.setName("小白");
        stu2.setBirthday(new Date());
        stu2.setMoney(19f);

        List<Student> list = new ArrayList<>();
        list.add(stu1);
        list.add(stu2);
        // 向model中存放list
        model.addAttribute("stuList", list);

        // 创建map数据
        HashMap<String, Student> map = new HashMap<>();
        map.put("stu1", stu1);
        map.put("stu2", stu1);

        model.addAttribute("map", map);
        return "02-list";








    }


}
